<template>
  <div class="videobox" @contextmenu.prevent="menuPlayer()">
    <!--<el-page-header @back="goBack"title="返回上一页"></el-page-header>-->
    <video-player
      class="video-player-box"
      ref="videoPlayer"
      :options="playerOptions"
      :playsinline="true"
      customEventName="customstatechangedeventname"
      @play="onPlayerPlay($event)"
      @pause="onPlayerPause($event)"
      @ended="onPlayerEnded($event)"
      @waiting="onPlayerWaiting($event)"
      @playing="onPlayerPlaying($event)"
      @loadeddata="onPlayerLoadeddata($event)"
      @timeupdate="onPlayerTimeupdate($event)"
      @canplay="onPlayerCanplay($event)"
      @canplaythrough="onPlayerCanplaythrough($event)"
      @statechanged="playerStateChanged($event)"
      @ready="playerReadied">
    </video-player>
  </div>

</template>

<script>
  // Similarly, you can also introduce the plugin resource pack you want to use within the component
  // import 'some-videojs-plugin'
  // import 'video.js/dist/lang/zh-CN.js'
  export default {
    data() {
      return {
        playerOptions: {
          playbackRates: [0.7, 1.0, 1.5, 2.0], //播放速度
          autoplay: false, //如果true,浏览器准备好时开始回放。
          muted: false, // 默认情况下将会消除任何音频。
          loop: false, // 导致视频一结束就重新开始。
          preload: 'auto', // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频（如果浏览器支持）
          language: 'zh-CN',
          aspectRatio: '16:9', // 将播放器置于流畅模式，并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字（例如"16:9"或"4:3"）
          fluid: true, // 当true时，Video.js player将拥有流体大小。换句话说，它将按比例缩放以适应其容器。
          sources: [{
            type: "video/mp4",
            src: '', //你的m3u8地址（必填）
          }],
          poster: "poster.jpg", //你的封面地址
          width: document.documentElement.clientWidth,
          notSupportedMessage: '此视频暂无法播放，请稍后再试', //允许覆盖Video.js无法播放媒体源时显示的默认信息。
          controlBar: {
            controls: '',
            oncontextmenu: 'return false',
            controlslist: 'nodownload',
            timeDivider: true,
            durationDisplay: true,
            remainingTimeDisplay: false,
            fullscreenToggle: true //全屏按钮
          }
        }
      }
    },
    mounted() {
      let videoUrl = this.$store.state.common.fileHost + this.$store.getters['common/getVideoUrl']
      this.playerOptions.sources[0].src = videoUrl //'https://cdn.theguardian.tv/webM/2015/07/20/150716YesMen_synd_768k_vp8.webm'
    },

    computed: {

      player() {
        return this.$refs.videoPlayer.player
      }
    },

    methods: {

      // 禁用视频鼠标右键菜单
      menuPlayer () {
        return false
      },

      onPlayerPlay(player) {
        console.log(player)
      },

      onPlayerPause(player) {
        console.log(player)
      },

      onPlayerEnded(){

      },

      onPlayerPlaying(){

      },

      onPlayerLoadeddata(){

      },
      onPlayerTimeupdate(){

      },

      onPlayerCanplay(){

      },

      onPlayerCanplaythrough(){

      },

      playerStateChanged(playerCurrentState) {

      },

      onPlayerWaiting () {

      },

      // player is ready
      playerReadied(player) {
        console.log('the player is readied', player)
      }
    }
  }
</script>
<style lang="less" >

  .videobox{
    height: 100%;
    width: 1100px;
    margin: 30px auto 0;
    .video-player-box{
      width: 100%;
      min-height: 638px;
      height: 100%;
    }
  }

  .video-js .vjs-current-time, .vjs-no-flex .vjs-current-time,.video-js .vjs-duration, .vjs-no-flex .vjs-duration,.vjs-time-divider{
    display: inline-block!important;
  }


  .video-js .vjs-big-play-button{
    left: 50%!important;
    top: 50%!important;
    transform: translate(-50%, -50%)!important;
  }

  .el-page-header {
    line-height: 40px;
  }

  .el-page-header:hover {
    cursor: pointer;
    color: #409eff;
  }

</style>
